import { type AxiosRequestConfig } from "axios";

/**
 * 响应数据
 */
export type ApiResponse<T = any> = {
  code: number;
  msg: string;
  data: T;
};

/**
 * 请求分页公共数据
 */
export type PageParams = {
  /**
   * 页码
   */
  page?: number;
  /**
   * 每页数量
   */
  page_size?: number;
};

/**
 * 通用查询
 */
export type WhereParams<T> = {
  where?: T;
  op?: Record<keyof T, OpModel>;
};

export type CommonPageParams<T> = PageParams & WhereParams<T>;

export enum OpModel {
  EQ = "=",
  NOT_EQ = "!=",
  IN = "in",
  NOT_IN = "not_in",
  BETWEEN = "between",
  NOT_BETWEEN = "not_between",
  LIKE = "like",
  GT = ">",
  GE = ">=",
  LT = "<",
  LE = "<=",
  NULL = "null",
  NOT_NULL = "not_null",
}

/**
 * 分页响应数据
 */
export type PageResponse<T = any> = {
  total: number;
  list: Array<T>;
  current_page: number;
  page_size: number;
};

/**
 * 请求mate
 */
export type RequestMateConfig = {
  mate?: {
    /**
     * 是否需要token
     * 为true时，自动添加token
     * 默认true
     */
    needToken?: boolean;
    /**
     * 响应后是否显示接口返回的信息
     * 默认true
     */
    showTip?: boolean;
  };
};

/**
 * 支持的请求配置
 */
export type RequestConfig = AxiosRequestConfig & RequestMateConfig;

/**
 * 状态码
 */
export enum Code {
  SUCCESS = 0,
  ERROR = 1,
  LOADING = 2,
  NOT_LOGIN = 401,
}
